 ################################################################################
##################09.Figure_5.R###############################################
################################################################################

#Load Data#

pols <- readRDS('pols_bjps')

library(tidyverse)

#Select only Denmark and relevant variables#

den <- pols %>%
  filter(country.name == 'Denmark') %>%
  dplyr::select(country.name, electionyear, year, scale_econsdw, scale_dispgini, 
         scale_ggini_inc1, scale_socioeconomicsal) %>%
  pivot_longer(cols = starts_with("scale"), names_to = 'Variable', values_to = 'value') %>%
  mutate(year = ifelse(Variable == 'scale_econsdw', year, electionyear)) 

#Make Figure#
library(ggplot2)

denmark <- ggplot(den, aes(x = year, y = value, linetype= Variable)) +
  geom_path() +
  geom_point(aes(shape = Variable)) +
  theme_bw() +
  labs(x = 'Year', y = 'Value') +
  xlim(1998, 2014) +
  theme(legend.position = 'bottom') +
  scale_linetype_discrete(labels = c('Disposable Income Inequality', 'Polarization', 'Income Sorting', 'Socioeconomic Salience')) +
  scale_shape_discrete(labels = c('Disposable Income Inequality', 'Polarization', 'Income Sorting', 'Socioeconomic Salience'))

#ggsave("figure_5.pdf", plot = denmark, , width = 11, height = 5, units = 'in')
